package com.yiibai.springmvc.jms.queue;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.springframework.jms.core.JmsTemplate;

public class ConsumerServiceImpl implements ConsumerService {

	private JmsTemplate jmsTemplate;

	private Destination destination;

	/**
	 * 接受消息
	 */
	public void receive(Destination d) {

		TextMessage tm = (TextMessage) jmsTemplate
				.receive(d == null ? destination : d);
		try {
			System.out.println("ConsumerService从队列" + destination.toString()
					+ "收到了消息：\t" + tm.getText());
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public void setDestination(Destination destination) {
		this.destination = destination;
	}

}
